<extend name="Public/base"/>

<block name="body">
    <div class="main-title">
        <h2>编辑商品</h2>
    </div>
    <form action="{:U()}" method="post" class="form-horizontal">
    
        <div class="form-item">
         <label class="item-label">商品分类</label>
           <div class="controls info">
        <select name="cid" id="parent">
            <option value="{$catepid.id}" >{$catepid.title}</option>
        </select>
        <select name="cid" id="parent">
            <option value="{$cateid.id}" >{$cateid.title}</option>
        </select>
        <select name="cid" id="parent">
            <option value="{$cate.id}" selected>{$cate.title}</option>
        </select>            
            </div>
        </div>
        
        <div style="display:none" id="info">
            <select name="cid">
                <option value="">请选择</option>
                <volist name="res" id="v">
                <option value="{$v.id}">{$v.title}</option>
                </volist>
            </select>
        </div>

        <div class="form-item">
            <label class="item-label">商品名称<span class="check-tips"></span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="name" value="{$edit.name}">
                <input type="hidden" class="text input-large" name="id" value="{$edit.id}">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">商品描述</label>
            <div class="controls">
                <input type="text" class="text input-large" name="content" value="{$edit.content}">
            </div>
        </div>
        
        <div class="controls">
                        <label class="item-label">分类图标</label>
                        <input type="file" id="upload_picture">
                        <input type="hidden" name="pic" id="pic" value=""/>
                        <div class="upload-img-box">
                        <notempty name="info['pic']">
                            <div class="upload-pre-item"><img src="__ROOT__{$info.pic|get_cover='path'}"/></div>
                        </notempty>
                        </div>
                    </div>


         <script type="text/javascript">
                    //上传图片
                    /* 初始化上传插件 */
                    $("#upload_picture").uploadify({
                        "height"          : 30,
                        "swf"             : "__STATIC__/uploadify/uploadify.swf",
                        "fileObjName"     : "download",
                        "buttonText"      : "上传图片",
                        "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                        "width"           : 120,
                        'removeTimeout'   : 1,
                        'fileTypeExts'    : '*.jpg; *.png; *.gif;',
                        "onUploadSuccess" : uploadPicture,
                        'onFallback' : function() {
                            alert('未检测到兼容版本的Flash.');
                        }
                    });
                    function uploadPicture(file, data){
                        var data = $.parseJSON(data);
                        var src = '';
                        if(data.status){
                            $("#pic").val(data.id);
                            src = data.url || '__ROOT__' + data.path;
                            $("#pic").parent().find('.upload-img-box').html(
                                '<div class="upload-pre-item"><img src="' + src + '"/></div>'
                            );
                        } else {
                            updateAlert(data.info);
                            setTimeout(function(){
                                $('#top-alert').find('button').click();
                                $(that).removeClass('disabled').prop('disabled',false);
                            },1500);
                        }
                    }
                    </script>


       <div class="form-item">
            <label class="item-label">是否热卖<span class="check-tips"></span></label>
            <div class="controls">
                <label class="radio"><input type="radio" name="is_hot" value="1" {$edit['is_hot']?'checked':''}>是</label>
                <label class="radio"><input type="radio" name="is_hot" value="0"  {$edit['is_hot']?'':'checked'}>否</label>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">是否上架<span class="check-tips"></span></label>
            <div class="controls">
                <label class="radio"><input type="radio" name="status" value="1"  {$edit['status']?'checked':''}>是</label>
                <label class="radio"><input type="radio" name="status" value="0" {$edit['status']?'':'checked'}>否</label>
            </div>
        </div>
         <div class="form-item">
            <button class="btn submit-btn" id="submit" type="submit" target-form="form-horizontal">提交</button>
            <button class="btn btn-return" type="reset">重置</button>
        </div>
    </form>
</block>

<block name="script">
    <script type="text/javascript">
        //导航高亮
        highlight_subnav('{:U('Shop/index')}');

      
            var info = $("#info").html();
            $("#parent").click(function(){
                $(".info").empty().append(info);
            })
            
            $(function(){
   $("body").on('change','select',function(){
    var id = $(this).val();
    var t = $(this);
    $.post("{:U('Shop/child')}", { id:id },
   function(res){
    if (res.status==1) {
        t.nextAll().remove();
        t.after(res.info);
    };
   });
   }) 
})

        
    </script>
</block>
